package com.example.exceldemo.service.impl;

import com.alibaba.excel.EasyExcel;
import com.example.exceldemo.entity.UserExcel;
import com.example.exceldemo.mapper.UserMapper;
import com.example.exceldemo.read.BasicExcelListener;
import com.example.exceldemo.read.DictListener;
import com.example.exceldemo.service.ImportService;
import com.example.exceldemo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author: yanhongwei
 * @Date: 2023/07/13 16:56:23
 * @Description: TODO
 */
@Service
@Slf4j
public class ImportServiceImpl implements ImportService {

    @Autowired
    UserService userService;

    @Override
    public void importDictData(MultipartFile file) {
        try {
            EasyExcel.read(file.getInputStream(), UserExcel.class, new BasicExcelListener(userService))
                    .sheet()
                    .doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
